﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Configurations.Controller;

namespace Pixysoft.Framework.Configurations.Core
{
    class XmlNode : IXmlNode
    {
        string elementName = null;

        string text = null;

        XmlPropertyCollection properties = new XmlPropertyCollection();

        List<IXmlNode> nodes = new List<IXmlNode>();

        public XmlNode(string elementName)
        {
            this.elementName = elementName;
        }

        public string ElementName
        {
            get
            {
                return elementName;
            }
            set { elementName = value; }
        }

        public string Text
        {
            get
            {
                return text;
            }
            set
            {
                text = value;
            }
        }

        public IXmlPropertyCollection Properties
        {
            get
            {
                return properties;
            }
        }

        public IXmlNodeCollection Node
        {
            get
            {
                return new XmlNodeCollection(nodes);
            }
        }

        public IXmlNodesCollection Nodes
        {
            get
            {
                List<IXmlNode> list = new List<IXmlNode>();
                foreach (IXmlNode node in nodes)
                    list.Add(node);
                return new XmlNodesCollection(nodes, list);
            }
        }

        public string Serialize()
        {
            return XmlNodeController.Instance.Serialize(this);
        }

        public string Serialize(bool indent)
        {
            return XmlNodeController.Instance.Serialize(this, indent);
        }

        public override string ToString()
        {
            return elementName;
        }

    }
}
